<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-setting"></i> 修改密码</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="form-box">
                <el-form ref="form" :model="form" label-width="80px" :rules="rules">
                    <el-form-item label="用户编号" prop="FUserNo">
                        <el-input v-model="form.FUserNo" :disabled="true"></el-input>
                    </el-form-item>
                    <el-form-item label="用户名称">
                        <el-input v-model="form.FUserName" :disabled="true"></el-input>
                    </el-form-item>
                    <el-form-item label="原始密码" prop="FOldPwd">
                        <el-input v-model="form.FOldPwd" show-password></el-input>
                    </el-form-item>
                    <el-form-item label="新密码" prop="FNewPwd">
                        <el-input v-model="form.FNewPwd" show-password></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">保存</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
import { fetchDataFromApi } from  '../../api/apiService'

export default {
    name: 'baseform',
    data() {
        return {
            form: {
               FUserNo:'登录用户的编号',
               FUserName:'登录用户的名称',
               FOldPwd:'',
               FNewPwd:''
            },
            rules: 
            {
                FUserNo: [{ required: true, message: '请输入用户编号', trigger: 'blur' }],
                FOldPwd: [{ required: true, message: '请输入原始密码', trigger: 'blur' }],
                FNewPwd: [{ required: true, message: '请输入新密码', trigger: 'blur' }]
            }
        };
    },
    created(){
        this.form.FUserNo = localStorage.getItem('ms_userno');
        this.form.FUserName = localStorage.getItem('ms_username');
    },
    methods: {
        onSubmit() {
            //this.$message.success('提交成功！');

            this.$refs.form.validate(valid => {
                if(valid)
                {
                    //this.$message.success('提交成功！');

                    this.form.ActionCode = "ChangePwd";
                    this.form.Token = localStorage.getItem('ms_token');
                    fetchDataFromApi(this.form).then(res => {
                        // console.log(res);
                        
                        if(res.Message == "OK")
                        {
                            this.$message.success(res.Info);
                            localStorage.setItem('ms_userno', '');
                            localStorage.setItem('ms_username', '');
                            localStorage.setItem('ms_token', '');
                            this.$router.push('/login');
                        }
                        else
                        {
                            this.$message.error(res.Info);
                        }
                    });

                }
            });
        }
    }
};
</script>